package org.apache.dubbo.demo.provider;

import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.rpc.service.GenericService;

public class Test1 {
    // dubbo泛化调用
    // https://blog.csdn.net/cjh_tostring/article/details/78438171
    // https://dubbo.apache.org/zh/docs/v2.7/user/examples/generic-reference/
    public static void main(String[] args) {
        ApplicationConfig application=new ApplicationConfig();

        application.setName("hello-world-app");
        RegistryConfig registryConfig =new RegistryConfig ();
        registryConfig.setAddress("zookeeper://47.100.120.240:2181?timeout=600000");


        ReferenceConfig<GenericService> rc = new ReferenceConfig<GenericService>();
        rc.setApplication(application);
        rc.setGeneric(true);
        rc.setInterface("org.apache.dubbo.demo.DemoService");
        rc.setRegistry(registryConfig);
        GenericService genericService = rc.get();


// 基本类型以及Date,List,Map等不需要转换，直接调用
        Object result = genericService.$invoke("sayHello", new String[]{"java.lang.String"}, new Object[]{"world"});


        System.out.println(result);

// 用Map表示POJO参数，如果返回值为POJO也将自动转成Map
//        Map<String, Object> person = new HashMap<String, Object>();
//        person.put("name", "xxx");
//        person.put("password", "yyy");
//// 如果返回POJO将自动转成Map
//        Object result = genericService.$invoke("findPerson", new String[]
//                {"com.xxx.Person"}, new Object[]{person});

    }
}
